<template>
  <div class="page-container">
    <el-button type="primary" @click="fetchInstances" style="margin-bottom: 20px;">
      刷新列表
    </el-button>

    <el-table :data="instances" border stripe style="width: 100%" v-loading="loading">
      <el-table-column align="center" prop="id" label="实例ID"></el-table-column>
      <el-table-column align="center" prop="processDefinitionId" label="流程定义ID"></el-table-column>
      <el-table-column align="center" label="操作" width="100">
        <template #default>
          <!-- 可扩展：查看变量、终止流程等 -->
          <el-button size="small" type="danger" disabled>终止</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import axios from 'axios'
import {ElMessage} from "element-plus";

const instances = ref([])
const loading = ref(false)

// 获取运行中的流程实例
const fetchInstances = async () => {
  loading.value = true
  try {
    const res = await axios.get('/api/workflow/instances/running')
    instances.value = res.data || []
  } catch (err) {
    console.error('获取运行中实例失败:', err)
    ElMessage.error('获取流程实例失败')
  } finally {
    loading.value = false
  }
}

onMounted(() => {
  fetchInstances()
})
</script>

<style scoped>
.page-container {
  padding: 20px;
}
</style>
